/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package loja;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.sql.Connection;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import loja.dao.JdbcUtils;
import loja.dominio.Venda;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.util.JRLoader;
import net.sf.jasperreports.view.JasperViewer;

/**
 *
 * @author Administrador
 */
public class Teste {
    public static void main(String[] args) {
       Teste t = new Teste();
       t.testarRelatorio();
    }

    private void testarRelatorio() {
        try {
            Venda venda = new Venda();
            venda.setId(6L);
            String caminhoRelJasper = "./reports/nota_fiscal.jasper";
            String caminhoSubRelJasper = "./reports/nota_fiscal_subrelatorio.jasper";
            Connection connection = JdbcUtils.getConexao();
                        
            InputStream relJasper = new FileInputStream(caminhoRelJasper);
            InputStream subRelJasper = new FileInputStream(caminhoSubRelJasper);
            Map parametros = new HashMap();
            JasperPrint impressao = null;
            // Parametros do relatorios
            JasperReport relatorioJasper = (JasperReport) JRLoader.loadObject(relJasper);
            JasperReport subrelatorioJasper = (JasperReport) JRLoader.loadObject(subRelJasper);
            parametros.put("ID_VENDA", new Long(6l));
            parametros.put("SUBREPORT_DIR", "./reports/");
            impressao = JasperFillManager.fillReport(relatorioJasper, parametros, connection);
            JasperViewer viewer = new JasperViewer(impressao, true);
            viewer.setVisible(true);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}
